home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 20 / Cream of the Crop 20 (Terry Blount) (1996).iso / program / pcl4w13.zip / LINE.C < prev    next >
Text File  |  1996-07-14  |  3KB  |  108 lines

  1. /*** line ***/
  2.  
  3. #include "windows.h"
  4. #include "pcl4w.h"
  5. #include "sioerror.h"
  6. #include "paint.h"
  7. #include "line.h"
  8.  
  9. extern HWND hMainWnd;
  10. extern int  OnLineFlag;
  11.  
  12. /* private */
  13.  
  14. static WORD RxSelector = 0;
  15. static WORD TxSelector = 0;
  16. static void FreeDOSmemory(void);
  17.  
  18. static void FreeDOSmemory(void)
  19. {if(RxSelector)
  20.    {GlobalPageUnlock(RxSelector);
  21.     GlobalDosFree(RxSelector);
  22.     RxSelector = 0;
  23.    }
  24.  if(TxSelector)
  25.    {GlobalPageUnlock(TxSelector);
  26.     GlobalDosFree(TxSelector);
  27.     TxSelector = 0;
  28.    }
  29. }
  30.  
  31. /* public */
  32.  
  33. int GoOnLine(int Port, int BaudCode, int RxQueSize, int TxQueSize)
  34. {DWORD dwValue;
  35.  int RetCode;
  36.  if(OnLineFlag) return TRUE;
  37.  /* allocate windows/DOS memory for receive buffer */
  38.  dwValue = GlobalDosAlloc(1<<(3+RxQueSize));
  39.  if(dwValue)
  40.    {/* get selector */
  41.     RxSelector = LOWORD(dwValue);
  42.     GlobalPageLock(RxSelector);
  43.    }
  44.  else
  45.    {/* memory allocation error */
  46.     RxSelector = 0;
  47.     MessageBox(hMainWnd,"Cannot allocate memory","ERROR",MB_ICONEXCLAMATION | MB_OK);
  48.     return FALSE;
  49.    }
  50.  /* pass selector to PCL4W */
  51.  RetCode = SioRxBuf(Port,RxSelector,RxQueSize);
  52.  if(RetCode<0)
  53.    {SioError(RetCode,"SioRxBuf");
  54.     FreeDOSmemory();
  55.     return FALSE;
  56.    }
  57.  if(SioInfo('I'))
  58.    {/* allocate windows/DOS memory for transmit buffer */
  59.     dwValue = GlobalDosAlloc(1<<(3+TxQueSize));
  60.     if(dwValue)
  61.       {/* get selector */
  62.        TxSelector = LOWORD(dwValue);
  63.        GlobalPageLock(TxSelector);
  64.       }
  65.     else
  66.       {/* memory allocation error */
  67.        TxSelector = 0;
  68.        MessageBox(hMainWnd,"Cannot allocate memory","ERROR",MB_ICONEXCLAMATION | MB_OK);
  69.        return FALSE;
  70.       }
  71.     /* pass selector to PCL4W */
  72.     RetCode = SioTxBuf(Port,TxSelector,TxQueSize);
  73.     if(RetCode<0)
  74.       {SioError(RetCode,"SioTxBuf");
  75.        FreeDOSmemory();
  76.        return FALSE;
  77.       }
  78.     DisplayLine("TX interrupts enabled");
  79.    }
  80.  /* reset Port */
  81.  RetCode = SioReset(Port,BaudCode);
  82.  if(RetCode<0)
  83.    {SioError(RetCode,"SioReset");
  84.     SioDone(Port); /* just in case */
  85.     FreeDOSmemory();
  86.     return FALSE;
  87.    }
  88.  SioParms(Port,NoParity,OneStopBit,WordLength8);
  89.  DisplayLine("Port reset\n");
  90.  /* set DTR & RTS */
  91.  SioDTR(Port,'S');
  92.  SioRTS(Port,'S');
  93. #if 0
  94.  /* set flow control */
  95.  SioFlow(Port,TRUE);
  96.  DisplayLine("Flow control enabled");
  97. #endif
  98.  /* Set FIFO level for 16550 */
  99.  if( SioFIFO(Port,LEVEL_8) ) DisplayLine("16550 UART");
  100.  /* clear PCL4C receive buffer */
  101.  SioRxClear(Port);
  102.  return TRUE;
  103. } /* end GoOnLine */
  104.  
  105. void GoOffLine(int Port)
  106. {SioDone(Port);
  107.  FreeDOSmemory();
  108. } /* end GoOffLine */